﻿/*
//退出
window.document.body.onbeforeunload = function () {
    var n = window.event.screenX - window.screenLeft;
    var b = n > document.documentElement.scrollWidth - 20;
    if (b && window.event.clientY < 0 || window.event.altKey) {
        if (!ExamDataManage.isCtrlChage)
            alert("关闭");
    } else {
        if (!ExamDataManage.isCtrlChage) {
            alert("刷新");
            return false;
        }
    }
};
*/
function Start() {
    if (ExamLoadManage.iscomplete == 1) {
        $("#dpcontent").hide();
        //出题
        $("#showSj").show();
        $("#mysubmit").show();
        //计时
        $('#countdown_dashboard').countDown({
            targetOffset: {
                'day': 0,
                'month': 0,
                'year': 0,
                'hour': ExamDataManage.comminfo.totalH,
                'min': ExamDataManage.comminfo.totalM,
                'sec': 0
            },
            onComplete: function () {
                $("body").mask("时间到自动交卷中请稍候......");
                OnSubmit();
            }
        });
    }
}
function onSubmitEx() {
    jqConfirm("你确定要交卷吗？", "提示", function (v) {
        if (v == 'ok') {
            $("body").mask("交卷处理中请稍候......");
            OnSubmit();
        }
    });
}

function OnSubmit() {
    //提交评分
    if (ExamLoadManage.iscomplete == 1) {
        if (eachallInfoSubmit()) {
            
            var pars = { kaoshiId: ExamDataManage.kaoshiId, examid: ExamDataManage.comminfo.examid, topall: JSON2.stringify(ExamDataManage.allSub) };



        AjaxExamManage.Post(KSConfig.URLAssembly.Test.Server.SaveExamALL, pars, function (data) {
            $("body").unmask();
            if (data.IsSuccess == 1) {
                //评分后不能再修改提交
                AjaxExamManage.isSubmit = false;
               
                window.opener = null;
                window.open('', '_self');
                window.close();
               
                
            }
            //提交服务器失败
            else {
                showErrorTip(data.Msg);
            }
        }, function (xml, text, thrown) {
            showErrorTip(text);
        });

        }
    }
}
//重新获得所以题目
function eachallInfoSubmit() {
      
    if (ExamDataManage.topicLen1 > 0) {

        $("div[id^='topic1_'] .stViewOption  .opbtn_r_checked").each(function () {
            var repOb = { answerid: 0, reply: '' };
            var testObList = { topic: 0, topicType: 0, score: 0, replyList: [] };
            testObList.topic = $(this).attr("tid");
            testObList.topicType = 1;
            repOb.answerid = $(this).attr("aid");
            testObList.replyList.push(repOb);
            ExamDataManage.allSub.push(testObList);
         
        });
    }
    //2
    if (ExamDataManage.topicLen2 > 0) {
        $("div[id^='topic2_']").each(function () {
            var temp = $(this);
            var testObList = { topic: 0, topicType: 0, score: 0, replyList: [] };
            testObList.topic = temp.attr("tid");
            
       
            $(".stViewOption  .opbtn_c_checked", temp).each(function () {
                var repOb = { answerid: 0, reply: '' };
                repOb.answerid = $(this).attr("aid");
                testObList.replyList.push(repOb);

            });
            ExamDataManage.allSub.push(testObList);
        });
    }
    //3
    if (ExamDataManage.topicLen3 > 0) {
        $("div[id^='topic3_'] .stViewOption  .opbtn_r_checked").each(function () {
        
            var repOb = { answerid: 0, reply: '' };
            var testObList = { topic: 0, topicType: 0, score: 0, replyList: [] };
            testObList.topic = $(this).attr("tid");
            testObList.topicType = 3;
            repOb.answerid = $(this).attr("aid");
            testObList.replyList.push(repOb);

            ExamDataManage.allSub.push(testObList);
        });
    }
    //4
    if (ExamDataManage.topicLen4 > 0) {
        $("div[id^='topic4_']").each(function () {
            var temp = $(this);
            var testObList = { topic: 0, topicType: 0, score: 0, replyList: [] };
            testObList.topic = temp.attr("tid");
            testObList.topicType = 4;
            $(".stViewSpaceInput", temp).each(function () {
                var repOb = { answerid: 0, reply: '' };

                repOb.answerid = $(this).attr("aid");
                repOb.reply = this.value;
                testObList.replyList.push(repOb);
              
            });
            ExamDataManage.allSub.push(testObList);
        });
    }
    //5
    if (ExamDataManage.topicLen5 > 0) {
        $("div[id^='topic5_'] textarea").each(function () {
            var repOb = { answerid: 0, reply: '' };
            var testObList = { topic: 0, topicType: 0, score: 0, replyList: [] };
            testObList.topic = $(this).attr("tid");
            testObList.topicType = 5;
            repOb.answerid = $(this).attr("aid");
            repOb.reply = $(this).val();
            testObList.replyList.push(repOb);

            ExamDataManage.allSub.push(testObList);
        });
    }
    //6
    if (ExamDataManage.topicLen6 > 0) {
            var spanRate = $("#spanRate").text();
          
            var repOb = { answerid: 0, reply: '' };
            var testObList = { topic: 0, topicType: 0, score: 0, replyList: [] };
            testObList.topic = ExamDataManage.topic6[0].id;
            testObList.topicType = 6;
            testObList.score = ((spanRate / 100) * ExamDataManage.topic6[0].score);
            testObList.replyList.push(repOb);

            ExamDataManage.allSub.push(testObList);
    }

    return true;
}

$(document).keydown(function (e) {
    if (e.keyCode == 8)//屏蔽退格键
    {
        e.keyCode = 0;
        e.returnValue = false;
    }
    if (e.keyCode == 13)//屏蔽回车键
    {
        e.keyCode = 0;
        e.returnValue = false;
    }
    if (e.keyCode == 116 ||(e.ctrlKey && e.keyCode == 82))//屏蔽F5刷新键
    {
        e.keyCode = 0;
        e.returnValue = false;
    }
   
});
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

function getParam(paramName) {
    paramValue = "";
    isFound = false;
    if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
        arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&");
        i = 0;
        while (i < arrSource.length && !isFound) {
            if (arrSource[i].indexOf("=") > 0) {
                if (arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase()) {
                    paramValue = arrSource[i].split("=")[1];
                    isFound = true;
                }
            }
            i++;
        }
    }
    return paramValue;
}


$(document).ready(function () {

    self.moveTo(0, 0);
    self.resizeTo(screen.availWidth, screen.availHeight);

    //参数初始化
    ExamDataManage.comminfo.examid = getParam("kc");
    ExamLoadManage.isNew = true;
    //
    $("#showSj").hide();
    $("#mysubmit").hide();

    //$("#layout").ligerLayout({ leftWidth: 210, allowLeftCollapse: false });

    $(document).bind("contextmenu", function (e) {
        return false;
    });
    //创建考场
    $("body").mask("考试数据初始化中，请稍候......");

    var pars = { examid: ExamDataManage.comminfo.examid };

    AjaxExamManage.Post(KSConfig.URLAssembly.Test.Server.InitExam, pars, function (data) {
       
        if (data.IsSuccess > 0) {



            ExamDataManage.kaoshiId = data.Data.id;
            ExamLoadManage.data = { kaoshiId: ExamDataManage.kaoshiId, examid: ExamDataManage.comminfo.examid };
            ExamLoadManage.ready();
            AjaxExamManage.isSubmit = true;


        }
        //提交服务器失败
        else {
            $("body").unmask();
            if (data.IsSuccess == -99) {
                showErrorTip("已经考过，不允许考");
            } else
                showErrorTip(data.Msg);
        }
    }, function (xml, text, thrown) {
        $("body").unmask();
        showErrorTip(text);
    });

});

//哈希表
var ViewLibHashTable = {
    data: {},

    //插入键为Key和值Value的数据
    put: function (key, value) {
        this.data[key] = value;
    },

    //返回键位Key对应值Value的数据
    get: function (key) {
        return this.data[key];
    },

    //移除哈希表Key键和Value值
    remove: function (key) {
        delete this.data[key];
    },

    //返回哈希表中是否存在键Key
    isKey: function (key) {
        return key in this.data;
    },

    //移除哈希表所有数据
    clear: function () {
        this.data = {};
    },

    //返回哈希表数据是否为空
    isEmpty: function () {
        return !this.length;
    }
};

var KSConfig = {
    URLAssembly: {
        Test: {
            Server: {
                    //得到考试
                GetExam: "../WebServer/ExamOnline.ashx?Action=GetExam",
                SaveExam: "../WebServer/ExamOnline.ashx?Action=SaveExam",
                SaveExamALL: "../WebServer/ExamOnline.ashx?Action=SaveExamALL",
                InitExam: "../WebServer/ExamOnline.ashx?Action=InitExam"
                  }
            }
      }
};


var ExamLoadManage = {
    isNew: false,
    typeTeam:0,
    data:null,
    action: 0,
    iscomplete:0,
    ready: function () {
        this.complete();
    },
    //页面加载完成之后
    complete: function () {
        AjaxExamManage.onlineExam();

    }
  
};
//提交后台
var AjaxExamManage = {
    isSubmit: false,
    _exmaType: 1,
    textJsonData: 0,
    isRefersh: false,
    unPostArry:[],
    userID: 0,
    //试卷
    onlineExam: function () {
       
        if (ExamLoadManage.isNew) {
            this.Post(KSConfig.URLAssembly.Test.Server.GetExam, ExamLoadManage.data, function (data) {

                if (data.IsSuccess == 1) {
                    SetExamTest.closeJson(data.Data);
                }
                //提交服务器失败
                else {
                    showErrorTip(data.Msg);
                }
            }, function (xml, text, thrown) {
                showErrorTip(text);
            });
        }

    },
    Post: function (_url, _pars, fcsuccess, fcerror) {
        $.ajax({
            type: "POST",
            url: _url,
            data: _pars,
            dataType: "json",
            async:true,
            //提交服务器成功
            success: fcsuccess,
            //提交服务器错误
            error: fcerror
        });
    }
};

//设置试卷
var SetExamTest = {
    isCommon: true,
    isInit: false,
    isAdmin: false,
    titleID: 0,
    topictypeIndex: 1,
    htmlBuild: "",
    closeJson: function (data) {
        if (data != null) {
            ExamDataManage.topicLen1 = data.topicLen1;
            ExamDataManage.topicscore1 = data.topicscore1;
            ExamDataManage.topicLen2 = data.topicLen2;
            ExamDataManage.topicscore2 = data.topicscore2;
            ExamDataManage.topicLen3 = data.topicLen3;
            ExamDataManage.topicscore3 = data.topicscore3;
            ExamDataManage.topicLen4 = data.topicLen4;
            ExamDataManage.topicscore4 = data.topicscore4;
            ExamDataManage.topicLen5 = data.topicLen5;
            ExamDataManage.topicscore5 = data.topicscore5;
            ExamDataManage.topicLen6 = data.topicLen6;
            ExamDataManage.topicscore6 = data.topicscore6;
            ExamDataManage.comminfo = data.comminfo;
            ExamDataManage.topic1 = data.topic1;
            // ExamDataManage.answer1 = data.answer1;
            ExamDataManage.topic2 = data.topic2;
            // ExamDataManage.answer2 = data.answer2;
            ExamDataManage.topic3 = data.topic3;
            // ExamDataManage.answer3 = data.answer3;
            ExamDataManage.topic4 = data.topic4;
            // ExamDataManage.answer4 = data.answer4;
            ExamDataManage.topic5 = data.topic5;
            // ExamDataManage.answer5 = data.answer5;
            ExamDataManage.topic6 = data.topic6;


            this.viewSubList();
        } //end if
    },
    //显示题目
    viewSubList: function () {
        this.InitTopic1();
        this.InitTopic2();
        this.InitTopic3();
        this.InitTopic4();
        this.InitTopic5();
        this.InitTopic6();
        //
        $(".E_E_L_I_C_R_Content").append(this.htmlBuild);

        if (ExamDataManage.topicLen6 > 0) {
            selectText();
        }
        //显示公共信息
        var tolcount = ExamDataManage.topicLen1 + ExamDataManage.topicLen2 + ExamDataManage.topicLen3 + ExamDataManage.topicLen4 + ExamDataManage.topicLen5 + ExamDataManage.topicLen6;
        $("#lbexamname").html(ExamDataManage.comminfo.examname);
        $("#lbtotaltime").html(ExamDataManage.comminfo.totaltime);
        $("#lbcountTopic").html(tolcount);
        $("#totalscore").html(ExamDataManage.comminfo.totalscore);
        $("#lbusername").html(ExamDataManage.comminfo.username);

        //
        $("body").unmask();
        //加载完成等待考试
        ExamLoadManage.iscomplete = 1;
    },
    //单选择题
    InitTopic1: function () {
        if (ExamDataManage.topicLen1 > 0 && ExamDataManage.topic1 != null && ExamDataManage.answer1 != null) {
            //生成试题
            this.htmlBuild = this.getTopicTypeDiv(1, (ExamDataManage.topicscore1 / ExamDataManage.topicLen1), ExamDataManage.topicscore1);
            this.htmlBuild += "<div class=\"E_E_L_I_C_R_C_Font\">";
            for (var i = 0; i < ExamDataManage.topicLen1; i++) {
                var Itemtopic = ExamDataManage.topic1[i];
                var ItemAswer = ExamDataManage.topic1[i].answer; //this.getTopicAnswerObje(Itemtopic.id, ExamDataManage.answer1);

                this.htmlBuild += this.getTopicOne(1, Itemtopic, ItemAswer, (i + 1), "opbtn_radio");
            }
            this.htmlBuild += "</div>";
            //体型序号增加
            this.topictypeIndex++;
        }
    },
    //多选
    InitTopic2: function () {
        if (ExamDataManage.topicLen2 > 0 && ExamDataManage.topic2 != null && ExamDataManage.answer2 != null) {
            //生成试题
            this.htmlBuild += this.getTopicTypeDiv(2, (ExamDataManage.topicscore2 / ExamDataManage.topicLen2), ExamDataManage.topicscore2);
            this.htmlBuild += "<div class=\"E_E_L_I_C_R_C_Font\">";
            for (var i = 0; i < ExamDataManage.topicLen2; i++) {
                var Itemtopic = ExamDataManage.topic2[i];
                var ItemAswer = ExamDataManage.topic2[i].answer; //this.getTopicAnswerObje(Itemtopic.id, ExamDataManage.answer2);
                this.htmlBuild += this.getTopicOne(2, Itemtopic, ItemAswer, (i + 1), "opbtn_checkBox");
            }
            this.htmlBuild += "</div>";
            //体型序号增加
            this.topictypeIndex++;
        }
    },
    //判断
    InitTopic3: function () {
        if (ExamDataManage.topicLen3 > 0 && ExamDataManage.topic3 != null && ExamDataManage.answer3 != null) {
            //生成试题
            this.htmlBuild += this.getTopicTypeDiv(3, (ExamDataManage.topicscore3 / ExamDataManage.topicLen3), ExamDataManage.topicscore3);
            this.htmlBuild += "<div class=\"E_E_L_I_C_R_C_Font\">";
            for (var i = 0; i < ExamDataManage.topicLen3; i++) {
                var Itemtopic = ExamDataManage.topic3[i];
                var ItemAswer = ExamDataManage.topic3[i].answer;  //this.getTopicAnswerObje(Itemtopic.id, ExamDataManage.answer3);

                this.htmlBuild += this.getTopicOne3(3, Itemtopic, ItemAswer, (i + 1));
            }
            this.htmlBuild += "</div>";
            //体型序号增加
            this.topictypeIndex++;
        }
    },
    //填空
    InitTopic4: function () {
        if (ExamDataManage.topicLen4 > 0 && ExamDataManage.topic4 != null && ExamDataManage.answer4 != null) {
            //生成试题
            this.htmlBuild += this.getTopicTypeDiv(4, (ExamDataManage.topicscore4 / ExamDataManage.topicLen4), ExamDataManage.topicscore4);
            this.htmlBuild += "<div class=\"E_E_L_I_C_R_C_Font\">";
            for (var i = 0; i < ExamDataManage.topicLen4; i++) {
                var Itemtopic = ExamDataManage.topic4[i];
                var ItemAswer = ExamDataManage.topic4[i].answer; //this.getTopicAnswerObje(Itemtopic.id, ExamDataManage.answer4);
                this.htmlBuild += this.getTopicOne4(4, Itemtopic, ItemAswer, (i + 1));
            }
            this.htmlBuild += "</div>";
            //体型序号增加
            this.topictypeIndex++;
        }
    },
    //问答题
    InitTopic5: function () {
        if (ExamDataManage.topicLen5 > 0 && ExamDataManage.topic5 != null && ExamDataManage.answer5 != null) {
            //生成试题
            this.htmlBuild += this.getTopicTypeDiv(5, (ExamDataManage.topicscore5 / ExamDataManage.topicLen5), ExamDataManage.topicscore5);
            this.htmlBuild += "<div class=\"E_E_L_I_C_R_C_Font\">";
            for (var i = 0; i < ExamDataManage.topicLen5; i++) {
                var Itemtopic = ExamDataManage.topic5[i];
                var ItemAswer = ExamDataManage.topic5[i].answer;
                //var ItemAswer = this.getTopicAnswerObje(Itemtopic.id, ExamDataManage.answer5);
                this.htmlBuild += this.getTopicOne5(5, Itemtopic, ItemAswer, (i + 1));
            }
            this.htmlBuild += "</div>";
            //体型序号增加
            this.topictypeIndex++;
        }
    },
    InitTopic6: function () {
        if (ExamDataManage.topicLen6 > 0 && ExamDataManage.topic6 != null) {

            this.htmlBuild += this.getTopicTypeDiv(6, (ExamDataManage.topicscore6 / ExamDataManage.topicLen6), ExamDataManage.topicscore6);
            this.htmlBuild += "<div class=\"E_E_L_I_C_R_C_Font\">";

            this.htmlBuild += this.getTopicOne6(6, ExamDataManage.topic6[0], 1);

            this.htmlBuild += "</div>";

        }
    },
    //获分类
    getTopicTypeDiv: function (topicTypeId, mtscore, sumscore) {
        var topicName = "";
        switch (topicTypeId) {
            case 1:
                topicName = "单项选择题";
                break;
            case 2:
                topicName = "多项选择题";
                break;
            case 3:
                topicName = "判断题";
                break;
            case 4:
                topicName = "填空题";
                break;
            case 5:
                topicName = "问答题";
                break;
            case 6:
                topicName = "打字题";
                break;
        }
        var _html = "<div class=\"E_E_L_I_C_R_C_Title\" id=\"topic" + topicTypeId + "\"><div class=\"E_E_L_I_C_R_C_T_SubType\">" + this.getTopicTypeNum() + topicName + "</div><div class=\"E_E_L_I_C_R_C_T_Explain\">说明:（<label style=\"COLOR: #369\" >(每小题" + mtscore + "分，共" + sumscore + "分)</label>）</div></div>"
        return _html;
    },
    getTopicOne: function (topicTypeId, topicItem, answerItem, index, classs) {
        var _htmstr = " <div id=\"topic" + topicTypeId + "_" + topicItem.id + "\" tid=\"" + topicItem.id + "\" class=\"stViewItem\"><div class=\"stViewHead\"><table><tbody><tr><td style=\"WHITE-SPACE: nowrap; VERTICAL-ALIGN: top\"><label style=\"FLOAT: left\" class=\"stViewOrdNum\">" + index + ".</label></td><td><div style=\"LINE-HEIGHT: 1.5em; VERTICAL-ALIGN: middle\">" + topicItem.title + "（）。<span class=\"stViewScore\">(" + topicItem.score + "分)</span></div></td></tr></tbody></table></div><div class=\"stViewCont\">";
        var _temp = "";

        for (var i = 0; i < answerItem.length; i++) {
            _temp += "<div class=\"stViewOption\"><a class=\"stViewOpBtn opbtn " + classs + "\" tid=\"" + topicItem.id + "\" aid=\"" + answerItem[i].id + "\" onclick=\"ViewLibMakeAnswer.checkOption(this,\'" + topicItem.id + "\',\'" + topicTypeId + "\',\'" + answerItem[i].id + "\');\" href=\"javascript:void(0)\"><label>(" + ExamDataManage.getUpperCase(i) + ") </label>" + answerItem[i].answer + "</a></div>";
        }
        _htmstr += _temp + "</div></div>";
        return _htmstr;
    },
    getTopicOne3: function (topicTypeId, topicItem, answerItem, index) {
        var _htmstr = " <div id=\"topic" + topicTypeId + "_" + topicItem.id + "\" class=\"stViewItem\"><div class=\"stViewHead\"><table><tbody><tr><td style=\"WHITE-SPACE: nowrap; VERTICAL-ALIGN: top\"><label style=\"FLOAT: left\" class=\"stViewOrdNum\">" + index + ".</label></td><td><div style=\"LINE-HEIGHT: 1.5em; VERTICAL-ALIGN: middle\">" + topicItem.title + "（）。<span class=\"stViewScore\">(" + topicItem.score + "分)</span></div></td></tr></tbody></table></div><div class=\"stViewCont\">";
        var _temp = "<div class=\"stViewOption\">";
        for (var i = 0; i < answerItem.length; i++) {
            _temp += "<a tyle=\"PADDING-RIGHT: 10px\" class=\"stViewOpBtn opbtn opbtn_radio\" tid=\"" + topicItem.id + "\" aid=\"" + answerItem[i].id + "\" onclick=\"ViewLibMakeAnswer.checkOption(this,\'" + topicItem.id + "\',\'" + topicTypeId + "\',\'" + answerItem[i].id + "\');\" href=\"javascript:void(0)\">" + answerItem[i].answer + "</a>&nbsp;&nbsp;&nbsp;";
        }
        _htmstr += _temp + "</div></div></div>";
        return _htmstr;
    },
    getTopicOne4: function (topicTypeId, topicItem, Itemanser, index) {
        //找到字符串替换成输入框
        var _temp1 = topicItem.title;

        for (var i = 0; i < Itemanser.length; i++) {
            var __A = "【.第" + Itemanser[i].code + "空.】";

            var _temp = "<input class=\"stViewSpace stViewSpaceInput\" type=\"text\" tid=\"" + topicItem.id + "\" aid=\"" + Itemanser[i].id + "\" onBlur=\"ViewLibMakeAnswer.changeInput(\'" + topicItem.id + "\',\'" + Itemanser[i].id + "\',\'" + Itemanser[i].code + "\',this.value);\" />";
            _temp1 = _temp1.replace(__A, _temp);
        }


        var _htmstr = " <div id=\"topic" + topicTypeId + "_" + topicItem.id + "\"  tid=\"" + topicItem.id + "\" class=\"stViewItem\"><div class=\"stViewHead\"><table><tbody><tr><td style=\"WHITE-SPACE: nowrap; VERTICAL-ALIGN: top\"><label style=\"FLOAT: left\" class=\"stViewOrdNum\">" + index + ".</label></td><td><div style=\"LINE-HEIGHT: 1.5em; VERTICAL-ALIGN: middle\">" + _temp1 + "<span class=\"stViewScore\">(" + topicItem.score + "分)</span></div></td></tr></tbody></table></div><div class=\"stViewCont\"></div></div>";

        return _htmstr;
    },
    getTopicOne5: function (topicTypeId, topicItem, ItemAswer, index) {
        var aid = 1;
        if (ItemAswer.length > 0) aid = ItemAswer[0].id;
        var _htmstr = " <div id=\"topic" + topicTypeId + "_" + topicItem.id + "\" class=\"stViewItem\"><div class=\"stViewHead\"><table><tbody><tr><td style=\"WHITE-SPACE: nowrap; VERTICAL-ALIGN: top\"><label style=\"FLOAT: left\" class=\"stViewOrdNum\">" + index + ".</label></td><td><div style=\"LINE-HEIGHT: 1.5em; VERTICAL-ALIGN: middle\">" + topicItem.title + "（）。<span class=\"stViewScore\">(" + topicItem.score + "分)</span></div></td></tr></tbody></table></div><div class=\"stViewCont\">";
        _htmstr += "答案：<textarea class=\"t60TextArea\" tid=\"" + topicItem.id + "\" aid=\"" + aid +"\"  onBlur=\"ViewLibMakeAnswer.changeInput5(\'" + topicItem.id + "\',\'" + aid + "\',this.value);\"></textarea>";
        _htmstr += "</div></div>";
        return _htmstr;
    },
    getTopicOne6: function (topicTypeId, topicItem, index) {


        var _htmstr = " <div id=\"topic" + topicTypeId + "_" + topicItem.id + "\" class=\"stViewItem\"><div class=\"stViewHead\"><table><tbody><tr><td style=\"WHITE-SPACE: nowrap; VERTICAL-ALIGN: top\"><label style=\"FLOAT: left\" class=\"stViewOrdNum\">" + index + ".</label></td><td><div style=\"LINE-HEIGHT: 1.5em; VERTICAL-ALIGN: middle\">" + topicItem.title + "<span class=\"stViewScore\"></span></div></td></tr></tbody></table></div><div class=\"stViewCont\">";


        _htmstr += "<div style=\"margin:5px 0px;\"><div >总字数：<span id=\"spanAllNum\">0</span>键入字数：<span id=\"spanNum\">0</span>错误数：<span id=\"spanError\">0</span>正确率：<span id=\"spanRate\">0</span>%</div>";
        _htmstr += "<div style=\"display:none;\"><textarea id=\"txtCh1\">" + topicItem.title + "</textarea></div>";
        _htmstr += "<div id=\"divMain\" style=\"position:relative; height:800px;   overflow-y:scroll;width:820; background-color:#74AEE0; border:solid 5px blue;\"><textarea id=\"txtInput\" disabled onkeyup=\"changeText();\" onBlur=\"ViewLibMakeAnswer.changeInput6(\'" + topicItem.id + "\',\'" + topicItem.score + "\',this.value);\" style=\"width:800px;word-break:break-all; word-wrap:break-word;  word-spacing:normal; letter-spacing:0px; margin:0px; border:none; padding:0px; position:absolute; top:0px; left:0px; padding-top:28px; height:800px; overflow-y:hidden; background-color:#74AEE0; color:#74AEE0;  line-height:60px; font-family:Consolas; font-size:24px;\"></textarea>";
        _htmstr += "<div id=\"divText\" onclick=\"getObj('txtInput').focus();\" style=\" z-index:2; word-spacing:0px; letter-spacing:0px; word-break:break-all; word-wrap:break-word; position:absolute; padding:0px; margin:0px; left:0px; width:800px; color:Yellow; line-height:60px; font-family:Consolas; font-size:24px;\"></div></div>";

        _htmstr += "</div></div>";
        return _htmstr;
    },
    getTopicAnswerObje: function (topicId, answer) {
        var _opItem, _opData = new Array();
        var anlen = answer.length;
        var newRow = 0;
        for (var i = 0; i < anlen; i++) {
            _opItem = answer[i];
            if (_opItem.topic == topicId) {
                _opData[newRow] = _opItem;
                newRow++;
            }
        }
        return _opData;
    },
    getTopicTypeNum: function () {
        switch (this.topictypeIndex) {
            case 1:
                return "一. ";
                break;
            case 2:
                return "二. ";
                break;
            case 3:
                return "三. ";
                break;
            case 4:
                return "四. ";
                break;
            case 5:
                return "五. ";
                break;
            case 6:
                return "六. ";
                break;
        }
    }
};
//做答试题
var ViewLibMakeAnswer = {
    //选择一个选项ID
    checkOption: function (own, topicId, mark, opID) {
        var _html;
        switch (mark) {
            case "1": //单
                $(own).parent("div").parent("div").find("a").each(function (i) {

                    if ($(this).hasClass("opbtn_r_checked")) {
                        $(this).removeClass("opbtn_r_checked").addClass("opbtn_radio");

                    }
                });
                if ($(own).hasClass("opbtn_r_checked")) {
                    $(own).removeClass("opbtn_r_checked").addClass("opbtn_radio");
                } else {
                    $(own).removeClass("opbtn_radio").addClass("opbtn_r_checked");
                }
                this.checkOptionT1(topicId, opID);
                break;
            case "2": //多
                var isselect = 0;
                if ($(own).hasClass("opbtn_c_checked")) {
                    $(own).removeClass("opbtn_c_checked").addClass("opbtn_checkBox");
                } else {
                    $(own).removeClass("opbtn_checkBox").addClass("opbtn_c_checked");
                    isselect = 1;
                }
                this.checkOptionT2(topicId, opID, isselect);
                break;
            case "3": //判断
                var issselect = 0;
                $(own).parent("div").find("a").each(function (i) {

                    if ($(this).hasClass("opbtn_r_checked")) {
                        $(this).removeClass("opbtn_r_checked").addClass("opbtn_radio");
                    }
                });
                if ($(own).hasClass("opbtn_r_checked")) {
                    $(own).removeClass("opbtn_r_checked").addClass("opbtn_radio");
                    issselect = 0;
                } else {
                    $(own).removeClass("opbtn_radio").addClass("opbtn_r_checked");
                    issselect = 1;
                }
                this.checkOptionT3(topicId, opID, issselect);
                break;
            default:
                _html = "";
                break;
        }



        //_html != "" && this.refHtml(own, _html);
    },

    //选择单选题的一个选项ID
    checkOptionT1: function (topicId, opID, isselect) {
        //提交单选
        var pars = { uid: ExamDataManage.comminfo.userid, topicid: topicId, topicType: 1, anserid: opID,kaoshiId:ExamDataManage.kaoshiId, isWrite: isselect,rn:Math.random() };
        this.onsbmit(KSConfig.URLAssembly.Test.Server.SaveExam, pars);
        return "";
    },
    //选择多选题的一个选项ID
    checkOptionT2: function (topicId, opID, isselect) {

        var pars = { uid: ExamDataManage.comminfo.userid, topicid: topicId, topicType: 2, anserid: opID,kaoshiId:ExamDataManage.kaoshiId, isWrite: isselect,rn:Math.random() };
        this.onsbmit(KSConfig.URLAssembly.Test.Server.SaveExam, pars);
        return "";

    },
    //判断
    checkOptionT3: function (topicId, opID, isselect) {
        var pars = { uid: ExamDataManage.comminfo.userid, topicid: topicId, topicType: 3, anserid: opID,kaoshiId:ExamDataManage.kaoshiId, isWrite: isselect ,rn:Math.random()};
        this.onsbmit(KSConfig.URLAssembly.Test.Server.SaveExam, pars);
        return "";
    },
    //填空
    changeInput: function (topicId, opID, code, val) {
        var pars = { uid: ExamDataManage.comminfo.userid, topicid: topicId, topicType: 4, anserid: opID,kaoshiId:ExamDataManage.kaoshiId, code:code, anval: val ,rn:Math.random()};


        this.onsbmit(KSConfig.URLAssembly.Test.Server.SaveExam, pars);
    },
    changeInput5: function (topicId,aid, val) {
        var pars = { uid: ExamDataManage.comminfo.userid, topicid: topicId, topicType: 5, anserid: aid, anval: val, kaoshiId: ExamDataManage.kaoshiId,rn:Math.random() };
        this.onsbmit(KSConfig.URLAssembly.Test.Server.SaveExam, pars);
    },
    changeInput6: function (topicId,score,val) {
        var spanRate = $("#spanRate").text();
        var pars = { uid: ExamDataManage.comminfo.userid, topicid: topicId, topicType: 6, spanRate: spanRate, anserid: 1, anval: "", kaoshiId: ExamDataManage.kaoshiId, score: score,rn:Math.random() };
        this.onsbmit(KSConfig.URLAssembly.Test.Server.SaveExam, pars);
    },
    //更新HTML
    refHtml: function (own, html) {
        $(own).parent("div").parent("div").html(html);
    },
    onsbmit: function (_action, pars) {

        if (AjaxExamManage.isSubmit) {
            
            AjaxExamManage.Post(_action, pars, function (data) {

                if (data.IsSuccess == 1) {
                   
                }
                //提交服务器失败
                else {
                    AjaxExamManage.unPostArry.push(pars);
                }
            }, function (xml, text, thrown) {
                AjaxExamManage.unPostArry.push(pars);
            });
        }//end
    }
};
var ExamDataManage = {
    topicLen1: 0, //(单项选择题)长度(0--没题)
    topicscore1:0,
    topicLen2: 0, //(多项选择题)长度(0--没题)
    topicscore2:0,
    topicLen3: 0, //(判断题)长度(0--没题)
    topicscore3:0,
    topicLen4: 0, //(填空择题)长度(0--没题)
    topicscore4:0,
    topicLen5: 0, //(问答题题)长度(0--没题)
    topicscore5:0,
    topicLen6: 0, //(打字题题)长度(0--没题)
    topicscore6:0,
    kaoshiId:0,
    comminfo: {
         examid:0,
         examname:"",
         userid:0,
         username: "",
         phone: "",
         department: "",
         workcode: "",
         email: "",
         modeid:"",
         modename:"",
         totaltopic:0,
         totalscore:0,
         totaltime:0,
         totalH:0,
         totalM:0
     },
     topic1: [],
     answer1: [],
     topic2: [],
     answer2: [],
     topic3: [],
     answer3: [],
     topic4: [],
     answer4: [],
     topic5: [],
     answer5: [],
     topic6: [],
     allSub:[],
     isCtrlChage: false,

     //获取对应的小写字母
     getLowerCase: function (num) {
         return String.fromCharCode(97 + num);
     },

     //获取对应的大写字母
     getUpperCase: function (num) {
         return String.fromCharCode(65 + num);
     },
    //文本转换为Json格式
    textToJson: function (text) {
        return JSON.textToJson(text);
    },
    //JSON格式转换为TEXT格式
    jsonToText: function (json) {
        return JSON.jsonToText(json);
    }
};